package com.olah.user.controller;

import com.olah.common.entity.po.user.UserHiddenRoots;
import com.olah.user.service.RootsService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import com.olah.common.entity.dto.UtilResponse;
import com.olah.common.entity.po.user.UserSearchRoots;

import javax.annotation.Resource;

/**
 * User Roots Controller
 */
@RefreshScope
@RestController
@RequestMapping("/user/roots")
public class RootsController {

    @Resource
    private RootsService service;

    /**
     * 更新用户的隐藏信息权限
     * @param info
     */
    @PostMapping(value = "/hidden")
    public UtilResponse<Boolean> updateHidden(@RequestBody UserHiddenRoots info) {
        return service.updateHidden(info) == 1
                ? UtilResponse.success("更新成功", true)
                : UtilResponse.error("保存失败, 请稍后再试");
    }

    /**
     * 获取用户的隐藏信息权限
     * @param targetId 目标用户 id
     */
    @GetMapping(value = "/hidden")
    public UtilResponse<UserHiddenRoots> queryHidden(@RequestParam("targetId") int targetId) {
        return UtilResponse.success(service.queryHidden(targetId));
    }

    /**
     * 更新用户的被搜索权限
     * @param info
     */
    @PostMapping(value = "/search")
    public UtilResponse<Boolean> updateSearch(@RequestBody UserSearchRoots info) {
        return service.updateSearch(info) == 1
                ? UtilResponse.success("更新成功", true)
                : UtilResponse.error("保存失败, 请稍后再试");
    }

    /**
     * 获取用户的被搜索权限
     * @param targetId 目标用户 id
     */
    @GetMapping(value = "/search")
    public UtilResponse<UserSearchRoots> querySearch(@RequestParam("targetId") int targetId) {
        return UtilResponse.success(service.querySearch(targetId));
    }

}
